[WPF] ExceptionValidationRule doesn't react to exceptions...

Posted by Darmak on Stack Overflow See other posts from Stack Overflow or by Darmak
Published on 2010-04-30T21:54:42Z Indexed on 2010/04/30 21:57 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

Hi, I have an ExceptionValidationRule on my TextBox:

<Window.Resources>
    <Style x:Key="textStyleTextBox" TargetType="TextBox">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

<TextBox x:Name="myTextBox"
    {Binding Path=MyProperty, ValidatesOnExceptions=True}"
    Style="{StaticResource ResourceKey=textStyleTextBox}" />

and MyProperty looks like that:

private int myProperty;

public int MyProperty
{
    get { return myProperty; }
    set
    {
        if(value > 10)
            throw new ArgumentException("LOL that's an error");
        myProperty = value;
    }
}

In DEBUG mode, application crashes with unhandled exception "LOL that's an error" (WPF Binding Engine doesn't catch this and I think it should...).

In RELEASE mode, everything works fine.

Can someone tell me, why the hell is this happening? And how can I fix this?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about exception